// pages/danger/index.js
//获取应用实例
const app = getApp()
const host = app.globalData.host
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputShowed: false,
    inputVal: "",
    condition:true,
    isShow:false,
    historyList:[ ],
    searList:[]
  },
  onReady(){
    this.getHistory();
  },
  getHistory(){
    var that = this;
    var token = wx.getStorageSync('token')
    wx.request({
      url: host + '/risk/history',
      method: 'GET',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        token: token
      },
      success(res) {
        console.log(res.data);
        if (res.data.code == 0) {
          that.setData({
            historyList: res.data.data
          })
        } else {
          app.globalData.isShow(res.data.msg);
        }
      },
      fail(res) {
        app.globalData.isShow(res.data.msg);
      }
    })
  },
  showInput: function () {
    this.setData({
      inputShowed: true
    });
  },
  hideInput: function () {
    this.setData({
      inputVal: "",
      inputShowed: false,
      isShow: false,
      condition: true
    });
    this.getHistory();
  },
  clearInput: function () {
    this.setData({
      inputVal: "",
      isShow: false,
      condition: true
    });
    this.getHistory();
  },
  inputTyping: function (e) {
    var that = this
    var token = wx.getStorageSync('token')
    this.setData({
      inputVal: e.detail.value,
      isShow:true,
      condition:false
    });
    var that = this;
    wx.request({
      url: host + '/files/match',
      method: 'GET',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        token: token,
        kw:e.detail.value
      },
      success(res){
        console.log(res.data);
        if(res.data.code == 0){
          that.setData({
            searList: res.data.data
        })
        }else{
          app.globalData.isShow(res.data.msg);
        }
      },
      fail(res){
        app.globalData.isShow(res.data.msg);
      }
    })
    console.log(this.data.inputVal);
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('onLoad')
    var that = this
  },
  delete(e){
    var token = wx.getStorageSync("token");
    var that = this;
    console.log(e.currentTarget.dataset.key);
    wx.request({
      url: host + '/risk/history',
      method: 'DELETE',
      header: {
        'content-type': 'application/json'
      },
      data: {
        token: token,
        kw: e.currentTarget.dataset.key
      },
      success(res) {
        console.log(res.data);
        if (res.data.code == 0) {
          that.setData({
            historyList: res.data.data
          })
        } else {
          app.globalData.isShow(res.data.msg);
        }
      },
      fail(res) {
        app.globalData.isShow(res.data.msg);
      }
    })
  },
  deleteAll(){
    this.setData({
      historyList:[]
    })
  }
})